package com.xinqi.modules.prepare.homework.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareHomeworkData;
import com.xinqi.modules.prepare.homework.domain.PrepareHomeworkEntity;
import com.xinqi.modules.prepare.homework.dto.req.PrepareHomeworkCreateDTO;
import com.xinqi.modules.prepare.homework.dto.req.PrepareHomeworkUpdateDTO;
import com.xinqi.modules.prepare.homework.dto.rsp.PrepareHomeworkResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区作业转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareHomeworkConvert {
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareHomeworkEntity create(PrepareHomeworkCreateDTO s);
    public abstract PrepareHomeworkCreateDTO create(PrepareHomeworkData s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareHomeworkEntity update(PrepareHomeworkUpdateDTO s, @MappingTarget PrepareHomeworkEntity t);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareHomeworkEntity update(PrepareHomeworkUpdateDTO s);

    @Mapping(target = "files", expression = "java(s.getFiles()!=null?com.xinqi.common.base.utils.json.JSON.parseList(s.getFiles(), com.xinqi.common.base.dto.CommonFileDTO.class):java.util.Collections.emptyList())")
    public abstract PrepareHomeworkResultDTO convert(PrepareHomeworkEntity s);
    public abstract PrepareHomeworkData convert(PrepareHomeworkResultDTO s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareHomeworkEntity copy(PrepareHomeworkEntity sources, @MappingTarget PrepareHomeworkEntity prepareHomeworkEntity);
}
